package com.xzl.xep.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xzl.xep.common.utils.DateUtil;
import com.xzl.xep.dao.BusinessDao;
import com.xzl.xep.pojo.Operator;
import com.xzl.xep.pojo.Payment;
import com.xzl.xep.service.CashService;

@Service
public class CashServiceImpl extends BaseServiceImpl implements CashService {

	@Resource
	protected BusinessDao business;
	
	@Override
	public List<Payment> getMinusList(Long companyId) {
		return getCashFlowList(companyId,0);
	}

	@Override
	public List<Payment> getPlusList(Long companyId) {
		return getCashFlowList(companyId,1);
	}
	
	
	
	private List<Payment> getCashFlowList(Long companyId, Integer type){
		if(companyId ==null || companyId ==0)
			return null;
		
		StringBuffer sb = new StringBuffer();
		
		sb.append("from Payment c where 1=1 ")
		  .append(" and createTime between '").append(DateUtil.getCurrentYMDstr()).append(" 00:00:00' ")
		  .append(" and '").append(DateUtil.getCurrentYMDstr()).append(" 23:59:59' ")
		  .append(" and c.companyId = ").append(companyId)
		  .append(" and type = ").append(type)
		  .append(" and way ='").append(Payment.CASH_WAY).append("'")
		  .append(" order by modifyTime desc");
		
		return dao.selectByHql(sb.toString());
	}

	
	@Override
	public Payment plusCash(Operator operator, Double money,String remark) {
		
		return business.plusCash(operator,money,remark);
	}

	@Override
	public Payment minusCash(Operator operator, Double money,String remark) {
		
		return business.minusCash(operator,money,remark);
	}

}
